package org.ielts.excel;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.StringReader;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFComment;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.ielts.configuration.ConfigurationClass;
import org.ielts.domain.base.Course;
import org.ielts.domain.base.SignCourse;
import org.ielts.domain.base.Student;
import org.ielts.domain.log.FreezeCourseLog;
import org.ielts.domain.log.OrderLessonLog;
import org.ielts.domain.log.SchoolLog;
import org.ielts.domain.security.User;
import org.ielts.excel.Excel09Test.Foo;
import org.ielts.service.ConsultantService;
import org.ielts.service.CourseService;
import org.ielts.service.FrontService;
import org.ielts.service.OrderLessonLogService;
import org.ielts.service.OrderLessonService;
import org.ielts.service.SchoolService;
import org.ielts.service.SignCourseService;
import org.ielts.service.StudentService;
import org.ielts.service.security.UserService;
import org.ielts.util.MapListWapper;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.validation.BindException;

import com.yifeng.ProfileContext;
import com.yifeng.dto.DtoTable;
import com.yifeng.dto.IDtoRow;
import com.yifeng.poi.CellReader;
import com.yifeng.poi.ExcelUtils;
import com.yifeng.utils.DateUtils;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { ConfigurationClass.class })
public class ExcelLastest {

	@Autowired
	private UserService userService;

	@Autowired
	ConsultantService consultantService;

	@Autowired
	CourseService courseService;

	MapListWapper<String, User> ccsm;
	MapListWapper<String, User> tutorsm;
	MapListWapper<String, Course> coursesm;

	Logger logger = LoggerFactory.getLogger("excelError");
	Logger savelogger = LoggerFactory.getLogger("oracleSave");

	Date upper = org.apache.commons.lang.time.DateUtils.addYears(new Date(), 10);

	@Before
	public void before() {

		ccsm = userService.findNameIdMapMatchRoleName("课程顾问");
		tutorsm = userService.findNameIdMapMatchRoleName("学习顾问");

		coursesm = courseService.findNameIdMap();
	}

	int startIndex = 0;
	int endIndex = 10385;

	boolean child = false;
	boolean card = false;
	boolean one2one = false;

	@Test
	public void importStudent() throws IOException, ParseException {

		File file = new File("D:\\Desktop\\原始数据\\修改后数据\\xls\\所有学员记录.xls");

		DtoTable table = ExcelUtils.book(file).sheet("Sheet1").addColumn("A", "name").addColumn("B", "stuNo")
				.addColumn("B", "another", new CellReader() {

					public Object read(HSSFCell cell) {
						HSSFComment comment = cell.getCellComment();
						if (comment != null) {
							String title = comment.getString().getString();
							return title;
						}
						return null;
					}
				}).parseToTable(1);

		int index = 0;
		for (IDtoRow iDtoRow : table) {
			index++;
			String name = (String) iDtoRow.get("name");
			String stuNo = (String) iDtoRow.get("stuNo");
			String another = (String) iDtoRow.get("another");
			Student student = null;

			StringBuilder stringBuilder = new StringBuilder();
			if (another != null) {
				stringBuilder.append(another);
			}

			if (StringUtils.isBlank(name)) {
				logger.debug("错误:没有姓名的学员");
			} else {
				name = name.trim();
				if (StringUtils.isBlank(stuNo)) {
					Iterable<Student> students = studentService.findByName(name);
					if (students.iterator().hasNext()) {
						for (Student oldStudent : students) {
							if (StringUtils.isNotBlank(oldStudent.getStuId()) && StringUtils.isNotBlank(stuNo)) {
								logger.debug(index + "警告:存在同名的学员," + name + ",学号为" + oldStudent.getStuId() + "，新学号为:"
										+ stuNo);
							}
						}
					} else {
						student = new Student();
						student.setName(name);
						student.setTitle(stringBuilder.toString());
					}
				} else {
					stuNo = stuNo.trim();
					if (stuNo.startsWith("9")) {
						stuNo = "0" + stuNo;
					}

					Iterable<Student> students = studentService.findByName(name);

					boolean exists = false;
					if (students.iterator().hasNext()) {
						for (Student oldStudent : students) {
							if (!stuNo.equals(oldStudent.getStuId())) {
								String log = "警告:同名" + name + "学号:" + oldStudent.getStuId() + ",新学号:" + stuNo;
								stringBuilder.append(log);
								// logger.debug(index + log);
								if (stringBuilder.length() > 200) {
									System.out.println(stringBuilder);
								}
							} else {
								exists = true;
								break;
							}
						}
					}
					if (!exists) {
						student = studentService.findByNo(stuNo);
						if (student != null) {
							String oldName = student.getName();
							logger.debug("错误:该学号" + stuNo + "已经分配给别的学员," + oldName);
							student = null;
						} else {
							student = new Student();
							student.setName(name);
							student.setStuId(stuNo);
							student.setTitle(stringBuilder.toString());
						}
					}
				}

				if (student != null) {
					studentService.createStudent(student);
				}
			}
		}
	}

	@Test
	public void test1() throws IOException, ParseException {

		File file = new File("D:\\Desktop\\原始数据\\修改后数据\\xls\\所有学员记录.xls");

		FileInputStream fileInputStream = new FileInputStream(file);
		HSSFWorkbook book = new HSSFWorkbook(fileInputStream);

		HSSFSheet sheet = book.getSheetAt(1);
		Iterator<Row> rowIterator = sheet.rowIterator();

		ArrayList<Student> students = new ArrayList<Student>();

		while (rowIterator.hasNext()) {
			Row row = rowIterator.next();
			int rowNum = row.getRowNum();

			int errorCount = 0;
			if (rowNum > startIndex && rowNum < endIndex) {
				Cell nameCell = row.getCell(0);
				Cell idCell = row.getCell(1);

				Student student = findStudent(nameCell, idCell);
				if (student == null) {
					logger.debug(rowNum + "行，无法找到学员");
					continue;
				}

				SignCourse signCourse = new SignCourse();

				FreezeCourseLog freezeCourseLog = new FreezeCourseLog();

				StringBuilder freezeLog = new StringBuilder();

				Iterator<?> cellIterator = row.cellIterator();
				while (cellIterator.hasNext()) {
					Object obj = cellIterator.next();
					HSSFCell cell = (HSSFCell) obj;
					int columnIndex = cell.getColumnIndex();

					// logger.debug("(" + rowNum + ":" + columnIndex + ")" +
					// cell);

					if (columnIndex == 2) {
						// 读取报名时间
						if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
							String source = cell.getStringCellValue();
							if (StringUtils.isNotBlank(source)) {
								source = source.trim();
								try {
									SimpleDateFormat df = new SimpleDateFormat("yyyy.MM.dd");
									Date resumeDate = df.parse(source);
									signCourse.setSignTime(resumeDate);
								} catch (ParseException ex) {
									SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
									try {
										Date resumeDate = df.parse(source);
										signCourse.setSignTime(resumeDate);
									} catch (ParseException e) {
										logger.debug(rowNum + "行，无法处理的日期：" + source);
									}
								}
							}
						} else {
							Date signTime = cell.getDateCellValue();
							signCourse.setSignTime(signTime);
						}

						if (signCourse.getSignTime() != null && signCourse.getSignTime().after(upper)) {
							logger.debug(rowNum + "行，报名日期超出范围");
							signCourse.setSignTime(null);
						}

					} else if (columnIndex == 3) {
						// 读取听课证号
						if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
							String lessonCard = cell.getStringCellValue().trim();
							if (lessonCard.length() > 20) {
								lessonCard = lessonCard.substring(0, 20);
							}
							signCourse.setLessonCard(lessonCard);
						} else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
							logger.debug(rowNum + "行，无效的卡号:" + cell);
						} else {
							double d = cell.getNumericCellValue();
							DecimalFormat df = new DecimalFormat("0");

							String lessonCard = df.format(d);
							signCourse.setLessonCard(lessonCard);
						}
					} else if (columnIndex == 4) {
						// 读取卡号
						if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
							String cardId = cell.getStringCellValue().trim();
							if (cardId.length() > 20) {
								cardId = cardId.substring(0, 20);
							}
							signCourse.setCardId(cardId);
						} else {
							double d = cell.getNumericCellValue();
							DecimalFormat df = new DecimalFormat("0");

							String cardId = df.format(d);
							signCourse.setCardId(cardId);
						}
					} else if (columnIndex == 5) {
						if (cell.getCellType() != Cell.CELL_TYPE_STRING) {
							logger.debug(rowNum + "行，无效的课程名称:" + cell);
						} else {
							StringBuilder sTitle = new StringBuilder();
							// 读取注册课程
							String courseName = cell.getStringCellValue();
							if (StringUtils.isBlank(courseName)) {
								Course course = findCourseByName("未知课程");
								signCourse.setCourse(course);
							} else {
								courseName = courseName.trim();
								Course course = findCourseByName(courseName);
								signCourse.setCourse(course);

								if (course == null) {
									Pattern pattern = Pattern.compile("^贵宾卡(\\d+)\\s*次\\s*$");
									Matcher matcher = pattern.matcher(courseName);

									if (matcher.find()) {
										String all = matcher.group(0);
										String t = matcher.group(1);
										System.out.println(t);

										int times = Integer.parseInt(t);
										signCourse.setTimes(times);

										course = findCourseByName("贵宾卡");
										signCourse.setCourse(course);

										sTitle.append(courseName);
									} else {
										// 尝试贵宾划次卡
										pattern = Pattern.compile("^贵宾划次卡(\\d+)\\s*次\\s*$");
										matcher = pattern.matcher(courseName);

										if (matcher.find()) {
											String all = matcher.group(0);
											String t = matcher.group(1);
											System.out.println(t);

											int times = Integer.parseInt(t);
											signCourse.setTimes(times);

											course = findCourseByName("贵宾卡");
											signCourse.setCourse(course);
											sTitle.append(courseName);
										} else {
											if (courseName.indexOf("雅思无限时") >= 0) {
												course = findCourseByName("雅思无限时");
												signCourse.setCourse(course);
												sTitle.append(courseName);
											} else if (courseName.indexOf("雅思无限思") >= 0) {
												course = findCourseByName("雅思无限时");
												signCourse.setCourse(course);
												sTitle.append(courseName);
											} else if (courseName.indexOf("沙龙自由人") >= 0) {
												course = findCourseByName("沙龙自由人");
												signCourse.setCourse(course);
												sTitle.append(courseName);
											} else if (courseName.indexOf("一对") >= 0) {
												course = findCourseByName("一对一");
												signCourse.setCourse(course);
												sTitle.append(courseName);
											} else if (courseName.indexOf("青少") >= 0 || courseName.indexOf("朗文") >= 0) {
												course = findCourseByName("少儿");
												signCourse.setCourse(course);
												sTitle.append(courseName);
											} else {
												logger.debug(rowNum + "行，课程名称:" + courseName + "无法找到");
												sTitle.append(courseName);
											}
										}
									}
								}
							}

							signCourse.setTitle(sTitle.toString());
						}
					} else if (columnIndex == 6) {
						// 读取期限
						if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
							double d = cell.getNumericCellValue();
							DecimalFormat df = new DecimalFormat("0");

							String term = df.format(d);
							signCourse.setCardId(term);
						} else {
							String term = cell.getStringCellValue().trim();
							signCourse.setTerm(term);
						}
					} else if (columnIndex == 7) {
						// 读取CC
						String ccName = cell.getStringCellValue();
						if (StringUtils.isNotBlank(ccName)) {
							User user = findCCByName(ccName.trim());
							if (user == null) {
								logger.debug(rowNum + "行，找不到名为" + ccName + "的CC");
							}
							student.setConsultor(user);
						}
					} else if (columnIndex == 8) {
						// 读取Tutor
						String tutorName = cell.getStringCellValue();
						if (StringUtils.isNotBlank(tutorName)) {
							User tutor = findTutorByName(tutorName.trim());
							if (tutor == null) {
								logger.debug(rowNum + "行，找不到名为" + tutorName + "的Tutor");
							}

							student.setTutor(tutor);
						}
					} else if (columnIndex == 9) {
						// 读取开课时间
						if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
							String source = cell.getStringCellValue();
							if (StringUtils.isNotBlank(source)) {
								source = source.trim();
								try {
									SimpleDateFormat df = new SimpleDateFormat("yyyy.MM.dd");
									Date beginTime = df.parse(source);
									signCourse.setBeginTime(beginTime);
								} catch (ParseException ex) {
									SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
									source = cell.getStringCellValue();

									try {
										Date beginTime = df.parse(source);
										signCourse.setBeginTime(beginTime);
									} catch (ParseException e) {
										logger.debug(rowNum + "行，无法处理的开课日期格式:" + source);
									}
								}
							}
						} else {
							Date beginTime = cell.getDateCellValue();
							signCourse.setBeginTime(beginTime);
						}

						if (signCourse.getBeginTime() != null && signCourse.getBeginTime().after(upper)) {
							logger.debug(rowNum + "行，课程开始时间超过当前时间10年");
							signCourse.setBeginTime(null);
						}
					} else if (columnIndex == 10) {
						// 读取结课时间
						if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
							String source = cell.getStringCellValue();
							if (StringUtils.isNotBlank(source)) {
								try {
									source = source.trim();
									SimpleDateFormat df = new SimpleDateFormat("yyyy.MM.dd");

									Date endTime = df.parse(source);
									signCourse.setEndTime(endTime);
								} catch (ParseException ex) {
									SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
									source = source.trim();
									try {
										Date endTime = df.parse(source);
										signCourse.setEndTime(endTime);
									} catch (ParseException e) {
										logger.debug(rowNum + "行，无法处理的日期格式：" + source);
									}
								}
							}
						} else {
							Date endTime = cell.getDateCellValue();
							signCourse.setEndTime(endTime);
						}

						if (signCourse.getEndTime() != null && signCourse.getEndTime().after(upper)) {
							logger.debug(rowNum + "行，报名日期超出范围");
							signCourse.setEndTime(null);
						}
					} else if (columnIndex == 11 || columnIndex == 12 || columnIndex == 13) {
						// 读取冻结概述
						if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC
								|| cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
							double d = cell.getNumericCellValue();
							DecimalFormat df = new DecimalFormat("0");

							String title = df.format(d);
							freezeLog.append(title);
						} else {
							String title = cell.getStringCellValue().trim();
							freezeLog.append(title);
						}
					} else if (columnIndex == 14) {
						// 读取冻结后日期
						if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
							String source = cell.getStringCellValue();
							if (StringUtils.isNotBlank(source)) {
								try {
									source = source.trim();
									SimpleDateFormat df = new SimpleDateFormat("yyyy.MM.dd");
									Date resumeDate = df.parse(source);
									freezeCourseLog.setResumeDate(resumeDate);
								} catch (ParseException ex) {
									SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
									try {
										Date resumeDate = df.parse(source);
										freezeCourseLog.setEndDate(resumeDate);
									} catch (ParseException e) {
										logger.debug(rowNum + "行，错误的冻结后日期日期输入：" + source);
									}
								}
							}
						} else {
							Date resumeDate = cell.getDateCellValue();
							freezeCourseLog.setEndDate(resumeDate);
						}

						if (freezeCourseLog.getEndDate() != null) {
							if (freezeCourseLog.getEndDate().after(upper)) {
								logger.debug(rowNum + "行，冻结后结课日期过大：" + freezeCourseLog.getEndDate());
							}
						}
					} else if (columnIndex == 15) {
						// 读取课时
						if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
							String timesStr = cell.getStringCellValue();
							String[] timeStrs = StringUtils.splitByCharacterType(timesStr);
							try {
								int times = Integer.parseInt(timeStrs[0]);
								signCourse.setTimes(times);
							} catch (NumberFormatException e) {
								logger.debug(rowNum + "行，错误的课次输入：" + timesStr);
							}
						} else {
							double d = cell.getNumericCellValue();
							signCourse.setTimes((int) d);
						}
					} else {
						/*
						 * HSSFComment comment = cell.getCellComment(); if
						 * (comment != null && comment.getString() != null) {
						 * 
						 * String title = comment.getString().getString();
						 * 
						 * BufferedReader br = new BufferedReader(new
						 * StringReader(title)); // 计算机名 String remark =
						 * br.readLine(); if (remark != null) { // 日期 String
						 * time = br.readLine(); String day = time == null ? ""
						 * : time.trim(); // 时间 while (time != null) { time =
						 * br.readLine(); if (time == null) { break; }
						 * 
						 * time = time.trim();
						 * 
						 * if (StringUtils.isNotBlank(time)) { time =
						 * time.trim(); Date date = signCourse.getSignTime(); if
						 * (date == null) { date = signCourse.getBeginTime(); if
						 * (date == null) { date = signCourse.getEndTime(); } }
						 * Foo f = parse(time, day, rowNum, date); if (f !=
						 * null) { Date beginTime = f.getBeginTime(); Date
						 * endTime = f.getEndTime(); String t =
						 * f.getTitle().trim();
						 * 
						 * if (beginTime.after(upper)) { logger.debug(rowNum +
						 * "行，日志开始时间过大"); } else if (endTime.after(upper)) {
						 * logger.debug(rowNum + "行，日志结束时间过大"); } else {
						 * 
						 * OrderLessonLog orderLessonLog = new OrderLessonLog();
						 * orderLessonLog.setStudent(student);
						 * orderLessonLog.setBeginTime(beginTime);
						 * orderLessonLog.setCreateTime(new Date());
						 * orderLessonLog.setEndTime(endTime);
						 * orderLessonLog.setLogTime(beginTime);
						 * orderLessonLog.setSignCourse(signCourse);
						 * orderLessonLog.setTitle(remark + " " + t);
						 * orderLessonLog.setValid(true);
						 * 
						 * student.getSchoolLogs().add(orderLessonLog); } } } }
						 * } else { logger.debug(rowNum + "行，日志无法读取"); } } else
						 * { errorCount++; if (errorCount > 2) { errorCount = 0;
						 * break; } }
						 */
					}

				}

				if (signCourse.getCourse() == null) {
					Course course = findCourseByName("未知课程");
					signCourse.setCourse(course);
				}

				freezeCourseLog.setTitle(freezeLog.toString().trim());

				freezeCourseLog.setSignCourse(signCourse);
				freezeCourseLog.setStudent(student);

				if (student != null) {
					String id = student.getId();
					User consultor = student.getConsultor();
					student = new Student();
					student.setId(id);
					student.setConsultor(consultor);
					student.getCourses().add(signCourse);
					student.getSchoolLogs().add(freezeCourseLog);
					students.add(student);
				}
			}
		}

		for (Student student : students) {

			if (student.getConsultor() != null) {
				// frontService.appointConsultor(student.getId(),
				// student.getConsultor().getId(), "历史导入数据");
			}
			if (student.getTutor() != null) {
				// frontService.appointTutor(student.getId(),
				// student.getTutor().getId(), "历史导入数据");
			}
			for (SignCourse signCourse : student.getCourses()) {
				String consultor = student.getConsultor() == null ? null : student.getConsultor().getId();
				signCourse = signCourseService.signUp(student.getId(), signCourse.getCourse().getId(), null,
						signCourse.getCardId(), signCourse.getLessonCard(), signCourse.getTitle(),
						signCourse.getTimes(), signCourse.getBeginTime(), signCourse.getEndTime(),
						signCourse.getSignTime(), consultor, null);

				for (SchoolLog schoolLog : student.getSchoolLogs()) {
					if (schoolLog instanceof FreezeCourseLog) {
						FreezeCourseLog freezeCourseLog = (FreezeCourseLog) schoolLog;
						if (freezeCourseLog.getEndDate() != null) {
							schoolService.freezCourse(student.getId(), signCourse.getId(), null,
									freezeCourseLog.getEndDate(), freezeCourseLog.getTitle());
						}
					}
					/*
					 * if (schoolLog instanceof OrderLessonLog) { OrderLessonLog
					 * orderLessonLog = (OrderLessonLog) schoolLog;
					 * orderLessonService.orderHistoryLesson(signCourse.getId(),
					 * orderLessonLog.getTitle(), orderLessonLog.getBeginTime(),
					 * orderLessonLog.getEndTime()); }
					 */
				}
			}
		}
	}

	@Autowired
	FrontService frontService;

	private Student findStudent(Cell nameCell, Cell idCell) {
		// 读取名称
		String name = nameCell.getStringCellValue().trim();

		List<Student> students = (List<Student>) studentService.findByName(name);
		if (students.size() == 1) {
			return students.get(0);
		}

		String stuId;
		if (idCell == null) {
			stuId = null;
		} else {

			if (idCell.getCellType() == Cell.CELL_TYPE_STRING) {
				stuId = idCell.getStringCellValue();
				if (stuId.length() > 200) {
					stuId = stuId.substring(0, 20);
				}
			} else {
				double d = idCell.getNumericCellValue();
				DecimalFormat df = new DecimalFormat("0");
				stuId = df.format(d);
				if (stuId.equals("0")) {
					stuId = "";
				}
			}
			if (stuId.startsWith("9")) {
				stuId = ("0" + stuId);
			}
		}
		if (StringUtils.isBlank(stuId)) {
			for (Student student : students) {
				if (StringUtils.isBlank(student.getStuId())) {
					return student;
				}
			}
		} else {
			for (Student student : students) {
				if (stuId.equals(student.getStuId())) {
					return student;
				}
			}
		}

		return null;
	}

	private Foo parse(String time, String day, int rowNum, Date signDate) {

		try {
			int year = 2000;
			int month;
			int d;

			String[] days = StringUtils.splitByCharacterType(day);
			if (days.length < 3) {
				logger.debug(rowNum + "行，无法处理的日期格式" + day);
				return null;
			} else if (days.length < 5) {
				if (signDate == null) {
					logger.debug(rowNum + "行，无法处理的日期格式" + day);
					return null;
				}
				Calendar calendar = Calendar.getInstance();
				calendar.setTime(signDate);

				year = calendar.get(Calendar.YEAR);

				month = Integer.parseInt(days[0]);
				d = Integer.parseInt(days[2]);
			} else {
				if (days[0].length() == 4) {
					year = Integer.parseInt(days[0]);
				} else {
					year = 2000 + Integer.parseInt(days[0]);
				}
				month = Integer.parseInt(days[2]);
				d = Integer.parseInt(days[4]);
			}
			String[] times = StringUtils.splitByCharacterTypeCamelCase(time);
			if (times.length < 7) {
				logger.debug(rowNum + "行，无法处理的日期时间格式" + day + " " + time);
				return null;
			}
			int h1 = Integer.parseInt(times[0]);
			int m1 = Integer.parseInt(times[2]);

			int h2 = Integer.parseInt(times[4]);
			int m2 = Integer.parseInt(times[6]);
			Calendar beginTime = Calendar.getInstance();
			beginTime.set(year, month, d, h1, m1);

			Calendar endTime = Calendar.getInstance();
			endTime.set(year, month, d, h2, m2);

			Foo f = new Foo();
			f.setBeginTime(beginTime.getTime());
			f.setEndTime(endTime.getTime());

			StringBuilder sb = new StringBuilder();
			for (int i = 7; i < times.length; i++) {
				String str = times[i];
				sb.append(str);
			}
			f.setTitle(sb.toString());

			return f;

		} catch (NumberFormatException ex) {
			logger.debug(rowNum + "行，无法处理的日期时间格式" + day + " " + time);
			return null;
		}
	}

	class Foo {
		Date beginTime;
		Date endTime;

		public Date getBeginTime() {
			return beginTime;
		}

		public void setBeginTime(Date beginTime) {
			this.beginTime = beginTime;
		}

		public Date getEndTime() {
			return endTime;
		}

		public void setEndTime(Date endTime) {
			this.endTime = endTime;
		}

		public String getTitle() {
			return title;
		}

		public void setTitle(String title) {
			this.title = title;
		}

		String title;
	}

	private User findTutorByName(String tutorName) {
		return tutorsm.getMap().get(tutorName.trim().toLowerCase());
	}

	private User findCCByName(String ccName) {
		return ccsm.getMap().get(ccName.trim().toLowerCase());
	}

	private Course findCourseByName(String courseName) {
		return coursesm.getMap().get(courseName.trim());
	}

	@Autowired
	StudentService studentService;

	@Autowired
	OrderLessonService orderLessonService;

	@Autowired
	OrderLessonLogService orderLessonLogService;

	@Autowired
	SignCourseService signCourseService;

	@Autowired
	SchoolService schoolService;
}
